package io.kiki.task.server.job.task.support.executor.job;

import cn.hutool.core.collection.CollUtil;
import io.kiki.task.server.job.task.support.JobExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;

@Slf4j
public abstract class AbstractJobExecutor implements JobExecutor, InitializingBean {

    @Override
    public void execute(JobExecutorContext context) {
        if (CollUtil.isEmpty(context.getTaskList())) {
            log.warn("待执行的任务列表为空. taskBatchId:[{}]", context.getTaskBatchId());
            return;
        }
        doExecute(context);
    }

    protected abstract void doExecute(JobExecutorContext context);

    @Override
    public void afterPropertiesSet() throws Exception {
        JobExecutorFactory.registerJobExecutor(getTaskInstanceType(), this);
    }
}
